home *** CD-ROM | disk | FTP | other *** search
- const
- BITS_PER_SET = 256;
- BYTES_PER_SET = 32;
- type
- bitset = array [0 .. BYTES_PER_SET] of byte;
-
- procedure empty(var s : bitset);
- ...
-
- function member(e : integer; var s : bitset) : boolean;
- ...
-
- procedure display(var s : bitset);
- ...
-
- {*
- * Expand set s1 into (256-element) bitset s2. length is
- * the length in bytes of s1. offset is the byte offset
- * in s2 that corresponds to the first byte of s1.
- *}
- procedure expand
- (var s1; var s2 : bitset; length, offset : byte);
- var
- i, j : integer;
- p : ^bitset;
- begin
- p := addr(s1);
- empty(s2);
- i := offset;
- for j := 0 to length - 1 do
- begin
- s2[i] := p^[j];
- i := i + 1;
- end;
- end;
-
- const
- LB = 21;
- HB = 50;
- var
- s : set of LB .. HB;
- b : bitset;
- i : integer;
- begin
- s := [22, 32, 42];
- expand(s, b, HB div 8 - LB div 8 + 1, LB div 8);
- write('b = '); display(b);
- for i := 0 to BITS_PER_SET do
- if member(i, b) then
- writeln(i:2, ' is a member of b');
- end.
-